package com.smartEdu.controller.app;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.smartEdu.commons.Session;
import com.smartEdu.commons.Tag_Tips;
import com.smartEdu.exception.ServiceException;
import com.smartEdu.response.Response;
import com.smartEdu.service.ChapterService;
import com.smartEdu.service.CourseCommentService;
import com.smartEdu.service.CourseService;

@Controller
@RequestMapping(value="/app/learn")
public class ChapterControl extends AppBaseController{
	
	@Autowired
	@Qualifier(value="appresponse")
	private Response respContext;
	
	@Autowired
	@Qualifier(value="chapterServiceImpl")
	private ChapterService chapter;
	
	@Autowired
	@Qualifier(value="courseAppServiceImpl")
	private CourseService courseService;
	
	@Autowired
	@Qualifier(value="courseCommentServiceImpl")
	private CourseCommentService courseCommentService;
	
	
	@RequestMapping(value="/course/chapter/content")
	public void getChapter(HttpServletRequest request,HttpServletResponse response){
		Session sess=null;
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			chapter.getChapter(sess);
		} 
		catch (ServiceException e) {
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}
		finally {
			SetResponse(response, sess);
		}
	}
	
	@RequestMapping(value="/course/chapter/comment")
	public void getCourseComment(HttpServletRequest request,HttpServletResponse response){
		Session sess=null;
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			courseCommentService.getCourseCommentServiceByPk(sess);
		} 
		catch (ServiceException e) {
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}
		finally {
			SetResponse(response, sess);
		}
	}
	
	@RequestMapping(value="/course/chapter/addcomment")
	public void addComment(HttpServletRequest request,HttpServletResponse response){
		Session sess=null;
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			courseCommentService.addCourseComment(sess);
		} 
		catch (ServiceException e) {
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}
		finally {
			SetResponse(response, sess);
		}
	}
	
	@RequestMapping(value="/course/chapter/coursedetail")
	public void getCourseInstructionDetail(HttpServletRequest request,HttpServletResponse response){
		Session sess=null;
		try {
			sess=GetSession();
			sess.put(Tag_Tips.REQUEST, GetParameter(request));
			courseService.getCourseInstructionByPk(sess);
		} 
		catch (ServiceException e) {
			sess.put(Tag_Tips.RESPCODE, Tag_Tips.ERROR);
		}
		finally {
			SetResponse(response, sess);
		}
	}

	@Override
	public String GetRespContent(Session sess) {
		// TODO Auto-generated method stub
		return respContext.GetRespContent(sess);
	}
	

}
